package com.zksk.admin.controller.order;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.zksk.admin.domain.orders.dto.OrdersCancelDto;
import com.zksk.admin.domain.orders.vo.OrdersCancelRequestVo;
import com.zksk.admin.service.orders.OrdersCancelService;
import com.zksk.common.core.domain.R;
import com.zksk.common.core.web.controller.BaseController;
import com.zksk.common.log.annotation.Log;
import com.zksk.common.log.enums.BusinessType;
import com.zksk.mbg.admin.domain.OrdersCancel;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Update;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 订单退订类 信息操作处理
 *
 * @author zksk
 */
@Slf4j
@RestController
@RequestMapping("/order/cancel")
@Api(value = "OrdersCancelController", tags = "订单退订相关接口")
public class OrdersCancelController extends BaseController {
    @Autowired
    private OrdersCancelService ordersCancelService;


    /**
     * 获取订单退订列表
     * @param requestVo
     * @return
     */
    @Log(title = "获取订单退订列表-分页", businessType = BusinessType.SELECT)
    @ApiOperation(value = "获取订单退订列表-分页")
    @PostMapping("/list")
    public R<IPage<OrdersCancelDto>> page(@RequestBody OrdersCancelRequestVo requestVo){

        IPage<OrdersCancelDto> resultPage  = ordersCancelService.orderCancelList(requestVo);
        return R.ok(resultPage, "获取退订订单列表数据成功");
    }

    /**
     * 获取退订订单表
     * @param ordersId
     * @return
     */
    @Log(title = "获取退订订单表", businessType = BusinessType.SELECT)
    @ApiOperation(value = "获取退订订单表")
    @GetMapping("/listByOrdersId")
    public R<List<OrdersCancel>> list(@RequestParam("ordersId") Long ordersId){
        List<OrdersCancel> list = ordersCancelService.list(
                new LambdaQueryWrapper<OrdersCancel>()
                        .eq(OrdersCancel::getOrdersId, ordersId)
        );
        return R.ok(list, "获取订单列表数据成功");
    }

    /**
     * 查看订单问题
     * @param ordersCancelId
     * @return
     */
    @Log(title = "退订订单管理", businessType = BusinessType.SELECT)
    @ApiOperation(value = "查看退订订单")
    @GetMapping("/{ordersQuestionId}")
    public R<OrdersCancel> select(@PathVariable("ordersQuestionId") Long ordersCancelId){

        OrdersCancel byId = ordersCancelService.getById(ordersCancelId);
        return R.ok(byId, "查看退订订单详情数据成功");
    }


    @Log(title = "退订订单管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    @ApiOperation(value = "删除退订订单(逻辑删除)")
    public R<String> remove(@PathVariable List<Long> ids) {
        ordersCancelService.removeBatchByIds(ids);
        return R.ok("删除成功");
    }

    /**
     * 新增订单问题
     * @param ordersCancel
     * @return
     */
    @Log(title = "退订订单管理", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation(value = "新增退订订单")
    public R<OrdersCancel> add(@Validated(Insert.class) @RequestBody OrdersCancel ordersCancel) {
        ordersCancelService.save(ordersCancel);
        return R.ok(ordersCancel,"新增成功");
    }

    /**
     * 更新退订订单
     * @param ordersCancel
     * @return
     */
    @Log(title = "退订订单管理", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation(value = "更新退订订单")
    public R<OrdersCancel> update(@Validated(Update.class) @RequestBody OrdersCancel ordersCancel) {
        ordersCancelService.updateById(ordersCancel);
        return R.ok(ordersCancel,"更新成功");
    }
}
